//
//  UILabel+Extension.swift
//  xinlangweibo
//
//  Created by yangshuo on 15/11/25.
//  Copyright © 2015年 yangshuo. All rights reserved.
//

import UIKit
extension UILabel{
    //color: UIColor = UIColor.redColor(),swift中的参数可以进行默认设置,调用方法时可以省略该参数代表使用默认的设置
    
    convenience init(title: String, color: UIColor = UIColor.darkGrayColor(), fontSize: CGFloat, screenInset: CGFloat = 0 ){
       self.init()
        text = title
        textColor = color
        font = UIFont.systemFontOfSize(fontSize)
        numberOfLines = 0
        //对屏幕缩进进行判断,如果为0默认居中对齐,否则左对齐
        if screenInset == 0{
            textAlignment = NSTextAlignment.Center
        }else{
    //label多行文本需要两个属性numberOfLines与label.preferredMaxLayoutWidth(合适的最大宽度),screenInset参数代表两边缩进的值
            preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * screenInset
            textAlignment = NSTextAlignment.Left
        }

        
    }
}
